import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
    {
        path: '/404',
        component: () => import('../views/404'),
        hidden: true,
        meta: {
            title: "页面找不到了"
        }
    },
    {
        path: '/',
        name: 'home',
        component: () => import('../views/home'),
        meta: {
            title: "首页"
        },
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/login'),
        meta: {
            title: "账号登录"
        }
    },
    {
        path: '/register',
        name: 'register',
        component: () => import('../views/register'),
        meta: {
            title: "账号注册"
        },
    },
    {
        path: '/cart',
        name: 'cart',
        component: () => import('../views/cart'),
        meta: {
            title: "我的购物车"
        }
    },
    {
        path: '/pai',
        component: () => import('../views/pai'),
        name: 'pai',
        redirect: 'pai/home',
        meta: {
            title: "拍卖行"
        },
        children: [
            {path: 'home', component: () => import('../views/pai/home/index'), name: "pai-home"},
            {
                path: 'more',
                component: () => import('../views/pai/more/index'),
                name: "pai-more",
                redirect: "more/today",
                children: [
                    {
                        path: 'today',
                        component: () => import('../components/pai/children/PaimaiMore_Today'),
                        name: "pai-more-today"
                    },
                    {
                        path: 'tomorrow',
                        component: () => import('../components/pai/children/PaimaiMore_Tomorrow'),
                        name: "pai-more-tomorrow"
                    },
                    {
                        path: 'yesterday',
                        component: () => import('../components/pai/children/PaimaiMore_Yesterday'),
                        name: "pai-more-yesterday"
                    },
                ]
            },
        ]
    },
    {
        path: '/pai-detail',
        name: 'pai-detail',
        component: () => import('../views/pai/detail'),
        redirect: '/pai-detail/describe',
        meta: {
            title: "商品详情"
        },
        children: [
            /*商品描述*/
            {
                path: 'describe',
                component: () => import('../components/pai/children/paiDetail/PaiDetail_Describe'),
                name: "pai-detail-describe"
            },
            /*出价记录*/
            {
                path: 'record',
                component: () => import('../components/pai/children/paiDetail/PaiDetail_RecordList'),
                name: "pai-detail-record"
            },
            /*服务保障*/
            {
                path: 'protection',
                component: () => import('../components/pai/children/paiDetail/PaiDetail_Protection'),
                name: "pai-detail-protection"
            },
            /*保证金须知*/
            {
                path: 'notice',
                component: () => import('../components/pai/children/paiDetail/PaiDetail_Notice'),
                name: "pai-detail-notice"
            },
        ]
    },
    {
        path: '/mine',
        name: 'mine',
        component: () => import('../views/mine'),
        meta: {
            title: "我的解忧"
        },
        redirect:"/mine/mine-info",
        children:[
            /*个人信息*/
            {
                path: 'mine-info',
                name: 'mine-info',
                component: () => import('../views/mine/info'),
                meta: {
                    title: "个人信息"
                }
            },
            /*个人信息*/
            {
                path: 'mine-footprint',
                name: 'mine-footprint',
                component: () => import('../views/mine/footprint'),
                meta: {
                    title: "我的足迹"
                },
            },
        ]
    },
    {
        path: '/t',
        name: 'test',
        component: () => import('../views/pai/detail'),
        meta: {
            title: "测试"
        },
    },
    {
        path: '*', redirect: '/404', hidden: true,
    }
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    // base: process.env.BASE_URL,
    // scrollBehavior: () => ({ y: 0 }),  // 滚动条 y=0
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
